# -*- coding: utf-8 -*-#
#-------------------------------------------------------------------------------
# 建立者:        潘炎珍  
# Name:         demo06
# Description:
# Author:       98745
# Date:         2019/3/3
#-------------------------------------------------------------------------------

class C(list):
    def __init__(self,*args):
        super().__init__(*args)
        self.count=0
    def __getitem__(self, index):
        self.count+=1
        return super().__getitem__(index)

c=C(range(10))
print(c)
c.reverse()
print(c)
del c[2:7]
print(c)
print(c.count)
print(c[1]+c[2])
print(c.count)

class C2(dict):
    def __init__(self,args):
        super().__init__(args)
        self.cout=0
    def __getitem__(self, key):
        self.cout+=1
        return super(C2,self).__getitem__(key)
d=C2({'name':'bill'})
print(d['name'])
print(d.get('age'))
d['age']=30
print(d['age'])
print(d.cout)

class M(str):
    def __new__(cls, *args, sep=' '):
        s=''
        for arg in args:
            s+=arg+sep
        index=-len(sep)
        print(index)
        if index==0:
            index=len(s)
        return str.__new__(cls,s[:index])
    def __init__(cls,*args,sep=' '):
        pass
cs1=M('a','b','c')
cs2=M('a','b','c',sep=',')
cs3=M('a','b','c',sep='')
print(cs1)
print(cs2)
print(cs3)